package com.yueyin.ui.main;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;

import com.yueyin.MainActivity.FragmentMain;

public class TouchEvent {


    /**
     * 播放模式
     */
    public static class OnPlayModelClick implements OnClickListener {

        PlayLogic playLogic;

        public OnPlayModelClick(PlayLogic playLogic) {
            this.playLogic = playLogic;
        }

        @Override
        public void onClick(View view) {
            playLogic.changePlayModel();
        }

    }

    /**
     * 上一曲
     */
    public static class OnLastClick implements OnClickListener {
        PlayLogic playLogic;

        public OnLastClick(PlayLogic playLogic) {
            this.playLogic = playLogic;
        }

        @Override
        public void onClick(View view) {
            playLogic.lastMusic();
        }

    }

    /**
     * 播放、暂停
     */
    public static class OnPlayPauseClick implements OnClickListener {

        PlayLogic playLogic;

        public OnPlayPauseClick(PlayLogic playLogic) {
            this.playLogic = playLogic;
        }

        @Override
        public void onClick(View view) {
            playLogic.playOrPause(true);
        }

    }

    /**
     * 下一曲
     */
    public static class OnNextClick implements OnClickListener {

        PlayLogic playLogic;

        public OnNextClick(PlayLogic playLogic) {
            this.playLogic = playLogic;
        }

        @Override
        public void onClick(View view) {
            playLogic.nextMusic();
        }
    }

    /**
     * 歌曲列表
     */
    public static class OnMenuClick implements OnClickListener {

        PlayLogic playLogic;

        public OnMenuClick(PlayLogic playLogic) {
            this.playLogic = playLogic;
        }

        @Override
        public void onClick(View view) {

        }
    }

    /**
     * 进度条
     */
    public static class OnSKChanged implements OnSeekBarChangeListener {

        PlayLogic playLogic;
        SeekBar seekBar;

        public OnSKChanged(PlayLogic playLogic,SeekBar seekBar) {
            this.playLogic = playLogic;
            this.seekBar = seekBar;
        }

        @Override
        public void onProgressChanged(SeekBar sk, int i, boolean b) {

        }

        @Override
        public void onStartTrackingTouch(SeekBar sk) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar sk) {
            playLogic.getMedia().seekTo(playLogic.getMedia().getDuration() * seekBar.getProgress() / seekBar.getMax());
        }

    }

    /**
     * 歌曲列表点击事件
     */
    public static class OnListItemClick implements OnItemClickListener {

        PlayLogic playLogic;

        public OnListItemClick(PlayLogic playLogic) {
            this.playLogic = playLogic;
        }

        @Override
        public void onItemClick(AdapterView<?> a, View v, int i, long l) {
            if ("".equals(playLogic.getCurrentMusicName())) {
                playLogic.position = i;
                playLogic.resetStart(i, true);
            } else if (playLogic.position == i) {
                playLogic.playOrPause(true);
            } else {
                playLogic.resetStart(i, true);
                playLogic.position = i;
            }

        }
    }

}
